﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AircraftBattleServer
{
    [Serializable]
    public class Aircraft
    {
        public int id;
        public int uid;
        public MyPoint position;
        public double angle;
        public bool alive;
        public int zombieCounter; // this is the counter of the loops the aircraft will
                                  // stay in the map data when it is hit. 
                                  // this is to allow client enough time to detect the hit

        public MyPoint Center
        {
            get
            {
                return new MyPoint(position.x + Constants.AircraftImageWidth / 2,
                    position.y + Constants.AircraftImageHeight / 2);
            }
        }

        public Aircraft(int id, MyPoint p, double angle = 0)
        {
            this.id = id;
            this.position = p;
            this.angle = angle;
            this.alive = true;
            this.zombieCounter = Constants.AircraftZombieCounter;
        }

        // When the zombie counter run down below 0, the aircraft 
        // will be removed from the mapdata
        public bool Die()
        {
            if (!this.alive)
            {
                this.zombieCounter--;
                // If the zombie period has expired
                if (this.zombieCounter < 0) return true;
            }

            return false;
        }

        public string GetImageName()
        {
            return "imgAircraft_" + this.id;
        }

    }
}
